/**
 * Advanced Software Engineering - assignment part 1 (monica Farrow)
 * JUnit ConstructorTestParcel class
 * 
 * Some of the methods in this class have been based on lecture notes provided by
 * Monica Farrow as a part of Software Engineering courses at Heriot-Watt University.
 */

package depotTests;

import static org.junit.Assert.*;
import org.junit.Test;

import depot.*;

public class ConstructorTestParcel {

	private int[] dim1;
	private Parcel pcl;

	/**
	 * Test length of parcelID
	 * Test contains 6 chars
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclIDLength1_1() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E00112", dim1, 2.55, 2);
	}

	/**
	 * Test length of parcelID
	 * Test contains 6 chars
	 * Test for exception message
	 */
	@Test
	public final void testPclIDLength1_2() {
		try {
			dim1 = new int[] {35,35,34};
			pcl = new Parcel("E00112", dim1, 2.55, 2);
			fail("Invalid parcelID - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("7 characters"));
		}
	}

	/**
	 * Test length of parcelID
	 * Test contains 8 chars
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclIDLength2() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E0000112", dim1, 2.55, 2);
	}

	/**
	 * Test length of parcelID
	 * Test ID = 7 chars
	 */
	@Test
	public final void testPclIDLength3() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 2.55, 2);
	}

	/**
	 * Test 1st char of parcelID
	 * Test first letter V
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclIDFirstChar1_1() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("V000112", dim1, 2.55, 2);
	}

	/**
	 * Test 1st char of parcelID
	 * Test first letter V
	 * Test for exception message
	 */
	@Test
	public final void testPclIDFirstChar1_2() {
		try {
			dim1 = new int[] {35,35,34};
			pcl = new Parcel("V000112", dim1, 2.55, 2);
			fail("Invalid parcelID - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("E, S or X"));
		}
	}

	/**
	 * Test 1st char of parcelID
	 * Test first letter L
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclIDFirstChar2() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("L000112", dim1, 2.55, 2);
	}

	/**
	 * Test 1st char of parcelID
	 * Test first letter S
	 */
	@Test
	public final void testPclIDFirstChar3() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("S000112", dim1, 2.55, 2);
	}

	/**
	 * Test 1st char of parcelID
	 * Test first letter X
	 */
	@Test
	public final void testPclIDFirstChar4() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("X000112", dim1, 2.55, 2);
	}

	/**
	 * Test last 6 chars of parcelID
	 * Test 1 char is 'o'
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclIDLastSix1_1() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E00o112", dim1, 2.55, 2);
	}

	/**
	 * Test last 6 chars of parcelID
	 * Test 1 char is 'o'
	 * Test for exception message
	 */
	@Test
	public final void testPclIDLastSix1_2() {
		try {
			dim1 = new int[] {35,35,34};
			pcl = new Parcel("E00o112", dim1, 2.55, 2);
			fail("Invalid parcelID - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("must be digits"));
		}
	}

	/**
	 * Test last 6 chars of parcelID
	 * Test last 6 all digits)
	 */
	@Test
	public final void testPclIDLastSix2() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 2.55, 2);
	}

	/**
	 * Test parcel dimensions
	 * Test dim1[0] = 0
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclDims1_1() {
		dim1 = new int[] {0,35,34};
		pcl = new Parcel("X000112", dim1, 2.55, 2);
	}

	/**
	 * Test parcel dimensions
	 * Test dim1[0] = 0
	 * Test for exception message
	 */
	@Test
	public final void testPclDims1_2() {
		try {
			dim1 = new int[] {0,35,34};
			pcl = new Parcel("X000112", dim1, 2.55, 2);
			fail("Invalid dimensions - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("must be > 0"));
		}
	}

	/**
	 * Test parcel dimensions
	 * Test dim1[1] = -1
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclDims2() {
		dim1 = new int[] {35,-1,34};
		pcl = new Parcel("S000112", dim1, 2.55, 2);
	}

	/**
	 * Test parcel dimensions
	 * Test dim1[2] = -2
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclDims3() {
		dim1 = new int[] {35,35,-2};
		pcl = new Parcel("E000112", dim1, 2.55, 2);
	}

	/**
	 * Test parcel dimensions
	 * Test all dims = 1
	 */
	@Test
	public final void testPclDims4() {
		dim1 = new int[] {1,1,1};
		pcl = new Parcel("X000112", dim1, 2.55, 2);
	}

	/**
	 * Test parcel dimensions
	 * Test all dims = 20
	 */
	@Test
	public final void testPclDims5() {
		dim1 = new int[] {20,20,20};
		pcl = new Parcel("X000112", dim1, 2.55, 2);
	}

	/**
	 * Test parcel volume
	 * Test vol = 226,981
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclVol1_1() {
		dim1 = new int[] {61,61,61};
		pcl = new Parcel("S000112", dim1, 2.55, 2);
	}

	/**
	 * Test parcel volume
	 * Test vol = 226,981
	 * Test for exception message
	 */
	@Test
	public final void testPclVol1_2() {
		try {
			dim1 = new int[] {61,61,61};
			pcl = new Parcel("S000112", dim1, 2.55, 2);
			fail("Invalid volume - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("cubic centimeters"));
		}
	}

	/**
	 * Test parcel volume
	 * Test vol = 226,500
	 */
	@Test
	public final void testPclVol2() {
		dim1 = new int[] {150,151,10};
		pcl = new Parcel("E000112", dim1, 2.55, 2);
	}

	/**
	 * Test parcel volume
	 * Test vol = 41,650
	 */
	@Test
	public final void testPclVol3() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("X000112", dim1, 2.55, 2);
	}

	/**
	 * Test parcel weight
	 * Test weight = 10.01
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclWeight1_1() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 10.01, 2);
	}

	/**
	 * Test parcel weight
	 * Test weight = 10.01
	 * Test for exception message
	 */
	@Test
	public final void testPclWeight1_2() {
		try {
			dim1 = new int[] {35,35,34};
			pcl = new Parcel("E000112", dim1, 10.01, 2);
			fail("Invalid weight - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("0.01 and 10.00 kilos"));
		}
	}

	/**
	 * Test parcel weight
	 * Test weight = 0.00
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclWeight2() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 0.00, 2);
	}

	/**
	 * Test parcel weight
	 * Test weight = 5.01
	 */
	@Test
	public final void testPclWeight3() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 5.01, 2);
	}

	/**
	 * Test parcel weight
	 * Test weight = 0.1
	 */
	@Test
	public final void testPclWeight4() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 0.1, 2);
	}

	/**
	 * Test parcel weight
	 * Test weight = 10.00
	 */
	@Test
	public final void testPclWeight5() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 10.00, 2);
	}

	/**
	 * Test parcel days in depot
	 * Test days = 0
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclDays1_1() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 8.25, 0);
	}

	/**
	 * Test parcel days in depot
	 * Test days = 0
	 * Test for exception message
	 */
	@Test
	public final void testPclDays1_2() {
		try {
			dim1 = new int[] {35,35,34};
			pcl = new Parcel("E000112", dim1, 8.25, 0);
			fail("Invalid days - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("1 and 28"));
		}
	}

	/**
	 * Test parcel days in depot
	 * Test days = 29
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testPclDays2() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 5.01, 29);
	}

	/**
	 * Test parcel days in depot
	 * Test days = 14
	 */
	@Test
	public final void testPclDays3() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 5.01, 14);
	}

	/**
	 * Test parcel days in depot
	 * Test days = 1
	 */
	@Test
	public final void testPclDays4() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 5.01, 1);
	}

	/**
	 * Test parcel days in depot
	 * Test days = 28
	 */
	@Test
	public final void testPclDays5() {
		dim1 = new int[] {35,35,34};
		pcl = new Parcel("E000112", dim1, 5.01, 28);
	}

}
